package socket

import (
	"bytes"
	"desktop-control.gateway.cn/handle/screen"
	"github.com/disintegration/imaging"
	"image/jpeg"
	"log/slog"
	"time"
)

func desktop() {
	for {
		select {
		case <-ticker.C:
			if len(hub.clients) > 0 {
				img := screen.Screen()
				_image := imaging.Resize(img, width, height, imaging.Lanczos)
				writer := bytes.NewBuffer(nil)
				_ = imaging.Encode(writer, _image, imaging.JPEG)
				var buf bytes.Buffer
				err := jpeg.Encode(&buf, img, &jpeg.Options{Quality: quality}) // 也可以使用jpeg, gif, etc.
				if err != nil {
					slog.Error("发生错误", "ERR", err)
				}
				_bytes := buf.Bytes()
				hub.SendToGroup("desktop", _bytes)
			}
		default:
			time.Sleep(time.Millisecond * 10)
		}
	}
}
